<!--<template>-->
<!--  <div>-->
<!--    <el-form-->
<!--      ref="etoak"-->
<!--      :model="form"-->
<!--      :rules="rules"-->
<!--      label-width="80px"-->
<!--      class="login-box"-->
<!--    >-->
<!--      <h3 class="login-title">欢迎登录</h3>-->
<!--      <el-form-item label="账号" prop="username">-->
<!--        <el-input-->
<!--          type="text"-->
<!--          placeholder="请输入账号"-->
<!--          v-model="form.username"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="密码" prop="password">-->
<!--        <el-input-->
<!--          type="password"-->
<!--          placeholder="请输入密码"-->
<!--          v-model="form.password"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" @click="submitForm('etoak')">登录</el-button>-->
<!--        <el-button type="primary" @click="resetForm('etoak')">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

<!--    <el-dialog title="温馨提示" :visible.sync="dialogVisible" width="30%">-->
<!--      <span>请输入账号和密码</span>-->
<!--      <span slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary">确 定</el-button>-->
<!--      </span>-->
<!--    </el-dialog>-->
<!--  </div>-->
<!--</template>-->

<!--<script>-->
<!--// import { login } from "../api/login.js";-->
<!--export default {-->
<!--  name: "Login",-->
<!--  data() {-->
<!--    return {-->
<!--      form: {-->
<!--        username: "",-->
<!--        password: ""-->
<!--      },-->

<!--      // 表单验证，需要在 el-form-item 元素中增加 prop 属性-->
<!--      rules: {-->
<!--        username: [-->
<!--          { required: true, message: "账号不可为空", trigger: "blur" },-->
<!--         -->
<!--        ],-->
<!--        password: [-->
<!--          { required: true, message: "密码不可为空", trigger: "blur" },-->
<!--       -->
<!--        ]-->
<!--      },-->

<!--      // 对话框显示和隐藏-->
<!--      dialogVisible: false-->
<!--    };-->
<!--  },-->
<!--  methods: {-->
<!--    submitForm(formName) {-->
<!--      // 为表单绑定验证功能-->
<!--      this.$refs[formName].validate(valid => {-->
<!--        // if (valid) {-->
<!--        //   login(this.form.username,this.form.password).then(response => {-->
<!--        //     console.log(response.data)-->
<!--        //     if(response.data.flag){-->
<!--        //       const token =response.data.data.key-->
<!--        //       const username = response.data.data.username-->
<!--        //       localStorage.setItem('token',token)-->
<!--        //       localStorage.setItem('username',username)-->
<!--        //       this.$router.push('/index')-->
<!--        //     }-->
<!--        //   });-->
<!--        // } else {-->
<!--        //   this.dialogVisible = true;-->
<!--        //   return false;-->
<!--        // }-->
<!--      });-->
<!--    },-->
<!--    resetForm(FormName) {-->
<!--      this.$refs[FormName].resetFields();-->
<!--    }-->
<!--  }-->
<!--};-->
<!--</script>-->

<!--<style lang="scss" scoped>-->
<!--.login-box {-->
<!--  border: 1px solid #dcdfe6;-->
<!--  width: 350px;-->
<!--  margin: 180px auto;-->
<!--  padding: 35px 35px 15px 35px;-->
<!--  border-radius: 5px;-->
<!--  -webkit-border-radius: 5px;-->
<!--  -moz-border-radius: 5px;-->
<!--  box-shadow: 0 0 25px #909399;-->
<!--}-->

<!--.login-title {-->
<!--  text-align: center;-->
<!--  margin: 0 auto 40px auto;-->
<!--  color: #303133;-->
<!--}-->
<!--</style>-->


<template>
  <div>
    <div class="mainheader">
      <div class="logo">
      </div>
      <div class="mainbutton">
        <el-row>
          <el-button round type="primary" @click="returnMenu">返回主界面</el-button>
        </el-row>
      </div>
    </div>
    <div class="loginbody">
      <div class="loginpicture">
      </div>
      <div class="logindata">
        <div class="logintext">
          <h2>管理员登录</h2>
        </div>
        <div class="formdata">
          <el-form ref="form" :model="form" :rules="rules">
            <el-form-item prop="account">
              <el-input
                  v-model="form.account"
                  clearable
                  placeholder="请输入账号"
              ></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input
                  v-model="form.password"
                  clearable
                  placeholder="请输入密码"
                  show-password
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="tool">
          <div>
            <el-checkbox v-model="checked" @change="remenber"
            >记住密码
            </el-checkbox
            >
          </div>
          <div>
            <span class="shou" @click="forgetpas">忘记密码？</span>
          </div>
        </div>
        <div class="butt">
          <el-button type="primary" @click.native.prevent="login('form')"
          >登录
          </el-button>
          <el-button class="shou" @click="register">注册</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {userLogin} from "@/request";
// import {validate} from "@vue/cli-service/lib/options";
export default {
  name: "login",
  data() {
    return {
      form: {
        password: "",
        account: "",
      },
      checked: false,
      rules: {
        account: [
          {required: true, message: "请输入用户名", trigger: "blur"},
          {max: 10, message: "不能大于10个字符", trigger: "blur"},
        ],
        password: [
          {required: true, message: "请输入密码", trigger: "blur"},
          {max: 10, message: "不能大于10个字符", trigger: "blur"},
        ],
      },
    };
  },
  methods: {
    // login(form) {
    //   this.$refs[form].validate((valid)=>{
    //     if(valid){
    //       userLogin(this.form)
    //           .then((res)=>{
    //             console.log("输出数据："+res)
    //           })
    //     }
    //   })
    login(form) {
      console.log("form里面的数据==>", this.form)
      this.$refs[form].validate((valid) => {
        if (valid) {
          userLogin(this.form)
              .then((res) => {
                console.log("输出数据：" + res.data.data)
                console.log("输出数据：" + res.data.msg)
                console.log("输出数据：" + res.data.code)
                if (res.data.code === 200) {
                  localStorage.setItem("ACCOUNT", this.form.account);
                  this.$message({
                    message: '登录成功',
                    type: 'success',
                    showClose: true
                  });
                  setTimeout(this.pushRouter, 1000);
                } else {
                  this.$message({
                    message: "账户号或密码错误",
                    type: 'error',
                    showClose: true
                  });
                }
              })
              .catch((err) => {
                this.$message({
                  message: `${err}`,
                  type: "success"
                })
              })
        }
      })
    },
    pushRouter() {
      this.$router.push("/add/index")
    },
    // this.$message({
    //   message: "登录成功啦",
    //   type: "success",
    //   // showClose: true,
    // });
    remenber(data) {
      this.checked = data
      if (this.checked) {
        localStorage.setItem("news", JSON.stringify(this.form))
      } else {
        localStorage.removeItem("news")
      }
    },
    forgetpas() {
      this.$message({
        type: "info",
        message: "功能尚未开发额😥",
        showClose: true
      })
    },
    register() {
      this.$message({
        type: "info",
        message: "功能尚未开发额😥",
        showClose: true
      })
    },
    //返回主页面
    returnMenu() {
      this.$alert('确认返回主界面？', '系统消息', {
        confirmButtonText: '确定',
        callback: action => {
          this.$router.push('/')
        }
      })
    }


    // this.$refs[form].validate((valid) => {
    //   if (valid) {
    //     login(this.form)
    //         .then((res) => {
    //           if (res.code === 200) {
    //             setToken(res.data.token);
    //             localStorage.setItem("USERNAME", res.data.username);
    //             this.$message({
    //               message: "登录成功啦",
    //               type: "success",
    //               showClose: true,
    //             });
    //             this.$router.replace("/");
    //           } else {
    //             this.$message({
    //               message: "账户名或密码错误",
    //               type: "error",
    //               showClose: true,
    //             });
    //           }
    //         })
    //         .catch((err) => {
    //           this.$message({
    //             message: "账户名或密码错误",
    //             type: "error",
    //             showClose: true,
    //           });
    //         });
    //   } else {
    //     return false;
    //   }
    // });
  },


}
</script>

<style scoped>
.mainheader {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.mainbutton {
}

.logo {
  width: 100%;
  height: 106px;
  background-image: url("../../images/logo.png");
  background-repeat: no-repeat;

}

.loginpicture {
  /*margin-left: 400px;*/
  width: 754px;
  height: 594px;
  background-image: url("../../images/1.png");
  background-repeat: no-repeat;
}

.loginbody {
  width: 100%;
  height: 100%;
  min-width: 1000px;
  /*!*background-image: url("../../images/1.png");*!*/
  background-size: 100% 100%;
  background: #00b0e8;
  background-position: center center;
  overflow: auto;
  background-repeat: no-repeat;
  position: fixed;
  line-height: 100%;
  /*margin-right: 600px;*/
  display: flex;
  /*flex-display: row;*/
  justify-content: center;
  align-items: center;
}

.logintext {
  margin-bottom: 20px;
  line-height: 50px;
  text-align: center;
  font-size: 30px;
  font-weight: bolder;
  color: white;
  text-shadow: 2px 2px 4px #000000;
}

.logindata {
  width: 400px;
  height: 300px;
  transform: translate(-50%);
  margin-left: 10%;

}

.tool {
  display: flex;
  justify-content: space-between;
  color: #606266;
}

.butt {
  margin-top: 10px;
  text-align: center;
}

.shou {
  cursor: pointer;
  color: #606266;
}

.el-button {
  margin-top: 50px;
  width: 150px;
}

/*ui*/
/* /deep/ .el-form-item__label {
  font-weight: bolder;
  font-size: 15px;
  text-align: left;
}

/deep/ .el-button {
  width: 100%;
  margin-bottom: 10px;

} */
</style>
